<!--
* @description 真仙装备设置
* @fileName zhenxian.vue
* @author huangyu
* @date 2023/04/13 13:44:29
!-->
<template>
    <div style="background:#fff;padding:10px;" >
        <el-row :gutter="20">
            <el-col :span="4">
                <el-input v-model="zbIdsStr" type="textarea" :rows="30"></el-input>
                <!-- <el-row>
                    <el-col :span="24" v-for="(item,index) in zbIdsStr" :key="index">
                        {{index+1}}、{{item}}
                    </el-col>
                </el-row> -->
            </el-col>
            <el-col :span="2">
                <el-button type="primary" @click="idsStringToArr">查询</el-button>
                <el-button type="primary" @click="clickImageText" style="margin:10px 0 0 0;">上传图片</el-button>
            </el-col>
            <el-col :span="18">
                <el-row v-if="list.length>0">
                    <el-col v-for="(item,index) in list" :key="index" :span="6">
                        <div>
                            <div style="height:36px;position: relative;float:left;">
                                <img :src="`https://7765-web-cloud0713-6g519i65f479e638-1301064135.tcb.qcloud.la/GamePublic/${item.icon}`" alt="">
                                <div class="zx-icon-bg"></div>
                            </div>
                            <div style="float:left;margin-left:10px;margin-bottom:20px;font-size:13px;">
                                <span>{{item.name}}</span>
                                <span>{{item.classStr[0]}}{{item.classStr[1]}}</span>
                                <span>{{item.sexStr}}</span>
                                <span>{{item.numbers?'*'+item.numbers:''}}</span>
                                <!-- <span style="display:inline-block;margin-left:50px;">{{item.id}}</span> -->
                                <div>
                                    {{item.fujia[0]}}
                                </div>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>

        <el-dialog title="图片识别文字" top="50px" width="1280px" :visible.sync="dialogImageText" v-if="dialogImageText" v-dialogDrag append-to-body>
            <div style="margin-top:-40px;"></div>
            <vOrcImageText @changeValue="changeValue" :isComponents="true"></vOrcImageText>
        </el-dialog>
    </div>
</template>

<script>
import { get } from '@/common/app.js'
import vOrcImageText from "@/page/ocr/ocr_img_text.vue"
export default {
    components: {vOrcImageText},
    data() {
        return {
            list: [],
            zbIdsStr: "",
            zxIds: [],
            zxIdsNumbers: {},

            dialogImageText: false,
        }
    },
    mounted() {
        // this.getData()
    },
    methods: {
        changeValue(list){
            this.zxIds = this.zxIds.concat(list)
            this.zxIds.forEach(item=>{
                this.zbIdsStr += item+'\n'
            })
            this.dialogImageText = false
            this.getData()
        },
        idsStringToArr(){
            if(this.zbIdsStr){
                // 统计id的数量
                console.log(this.zbIdsStr.split("\n"))
                let strArr = this.zbIdsStr.split("\n")
                if(strArr){
                    strArr.forEach(item=>{
                        let id = item.split("|")[0]
                        let money = item.split("|")[1]
                        let type = item.split("|")[2]
                        console.log(id,money,type)
                        this.zxIds.push(id)
                    })
                }
                // this.zxIds = this.zbIdsStr.split("\n").split("|")
                console.log(this.zxIds)
                this.getData()
            }else{
                this.$message.error("请先在左侧输入物品id!")
            }
        },
        getData(){
            var res = {};
            this.zxIds.forEach(function(e){ res[e] = res[e]>=1?res[e]+1:1});
            this.zxIdsNumbers = res
            let params = {
                type: 'getGoods',
                api: 'api-goods-list',
                token: this.token,
                data: {
                    ids: this.zxIds,
                },
            }
            get('game', params).then(res => {
                if (res) {
                    this.list = res.data
                    console.log(this.zxIdsNumbers)
                    this.list.forEach(item=>{
                        for(var i in this.zxIdsNumbers){
                            if(item.id==String(i)){
                                item.numbers = this.zxIdsNumbers[i]
                            }
                        }
                    })
                    console.log(this.list)
                }
            })
        },
        clickImageText(){
            this.dialogImageText = true
        },
    },
}
</script>

<style scoped></style>